home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: leeds.ac.uk!news
- From: csyamc@scs.leeds.ac.uk (A M Casey)
- Subject: malloc help needed
- Message-ID: <1996Mar28.113702.15788@leeds.ac.uk>
- NNTP-Posting-Host: csgi08.leeds.ac.uk
- Organization: The University of Leeds, School of Computer Studies
- Date: Thu, 28 Mar 1996 11:37:02 +0000 (GMT)
-
- As requested, here is the code that I cant suss out. I think the problem might
- be something to do with allocating memory in different functions,
-
- void PositionSelectCallback(Widget w,
- XtPointer clientData,
- XtPointer callData)
-
- /* a standard callback function in X/motif*/
-
- char *ItemName;
- /* stuff deleted */
- ItemName=malloc(20);
- XmStringGetLtoR(ItName, XmSTRING_DEFAULT_CHARSET, &ItemName);
- /*this assigns a string to ItemName (works fine) */
-
- ItemSelectCallback(ItemName,0);
-
- /* calls another function */
-
-
- void ItemSelectCallback(char *ItemName,
- int Flag)
-
- int NoOfItems;
- char *Item[20];
-
- printf("the name is fine -%s\n",ItemName);
- NoOfItems = GetInfoFromFile(Item,ItemName,Flag);
- printf("the name is not ok now - %s\n",ItemName);
-
-
- now then, obviously GetInfoFromFile changes ItemName, or rather
- the area of memory it points to, but I have not changed it in any
- way, it is just for comparisons with other strings read in.....
-
- int GetInfoFromFile(char *Item[20],char *ItemName,int Flag)
- char *tempcontents[50];
-
- for(count = 0; count <=20;count++)
- {
- Item[count] = malloc(50);
- }
- for(count = 0; count <=50;count++)
- {
- tempcontents[count] = malloc(50);
- }
-
-
- The only dodgy thing is that I'm declaring Item and allocating
- memory to it in a different function, but as far as I know this
- shouldnt be a problem. Everything else in the functions is stuff
- I've done for years, and it all works fine, it's just this memory
- allocation which seems to be messing up.
-
- Cheers for your help
-
- Andy
-